<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
<title>明细信息</title>
	<%@ include file="/resources/js/easyui/taglibs.jsp"%>
	<%@ include file="/resources/js/easyui/_easyui.jsp"%>
	<%@ include file="/resources/js/easyui/_message.jsp"%>
	<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
	<form id="addform">
		<table class="tableForm" style="width: 100%;">

			<tr>
				<th align="right" valign="top"><label>所属用户组：</label></th>
				<td>
					<c:forEach items="${userGroups}" var="userGroup" varStatus="status">
					<input type="radio" name="roleid" value="${userGroup.userGroupid}" <c:if test="${status.index == 0}">checked="checked"</c:if>>${userGroup.textCN}
					</c:forEach> 
				</td>
			</tr>

			<%--<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>邮箱地址：</label></th>
				<td><input class="easyui-validatebox" name="email"
					style="width:200px" data-options="required:true,validType:'email'" /></td>
			</tr>--%>

			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>用户名：</label></th>
				<td><input class="easyui-validatebox" name="username"
					style="width:200px"
					data-options="required:true,validType:'username'" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>手机号：</label></th>
				<td><input class="easyui-validatebox" name="mobile"
					style="width:200px" data-options="required:true,validType:'mobile'" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>用户密码：</label></th>
				<td><input class="easyui-validatebox" name="password"
					type="password" id="password" style="width:200px"
					data-options="required:true,validType:'passwordlegth'" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>确认密码：</label></th>
				<td><input class="easyui-validatebox" type="password"
					style="width:200px" data-options="required:true"
					validType="confirmPassword['#password']" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>用户属性：</label></th>
				<td><input name="property" style="width:200px;height:80px"
					data-options="multiline:true" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>备注：</label></th>
				<td><input name="remark" style="width:200px;height:80px"
					data-options="multiline:true" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>有效年限：</label></th>
				<td><input type="radio" name="timeDifference" value="1"
					checked="checked">1年 <input type="radio"
					name="timeDifference" value="2">2年 <input type="radio"
					name="timeDifference" value="3">3年</td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>用户状态：</label></th>
				<td><input type="radio" name="state" value="2"
					checked="checked">暂停 <input type="radio" name="state"
					value="1">启用</td>
			</tr>

		</table>
	</form>

	<script type="application/javascript">
		
	function add(){
		
		if($("#addform").form('validate')){
			$("#password").val(createPassword($("#password").val(),$("#password").val()));
			$.ajax({
				url:'${basePath}web/childuser/addchiilduserinfo',
				type : 'POST',
				data : $("#addform").serialize(),
				async : false,
				traditional:true,
				error: function (response) {
					ViewHelper.func.ajaxErrorMessage(response);
				},
				success: function (ret) {
					if(ret.result) {
						$.messager.alert('提示信息！',ret.info,'info');
						parent.view.closeAddWin(1);
						$("#addform").form('clear');
					}else{
						$.messager.alert('提示','保存失败!','error');
					}
				}
			});
		}
	}
	
	/* 验证手机号码、用户名或邮箱是否存在 */
	function validatorDataOnlien(value){
		var result = true;
		$.ajax({
			url:'${basePath}web/childuser/vaildUserInfo',
			async: false, 
			type : 'GET',
            data: {"vaildatorValue": value},
			traditional:true,
			success: function (ret) {
				result = ret.vaildatorResult;
			}
		});
		return result;
	}
	
	$.extend($.fn.validatebox.defaults.rules, {
		email: {
			validator: function(value, param) {
				if(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)){
					if(validatorDataOnlien(value)){
						 
						 $.fn.validatebox.defaults.rules.email.message = '邮箱已经存在,请更换其他邮箱地址';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.email.message = '请输入正确的邮箱地址';
					return false;
				}
				return true;
			},
			message: ''
		},
		mobile: {
			validator: function(value, param) {
				if(/^(?:13\d|15\d|18\d|17\d|14\d)-?\d{5}(\d{3}|\*{3})$/.test(value)){
					if(validatorDataOnlien(value)){
						 
						 $.fn.validatebox.defaults.rules.mobile.message = '手机号码已经存在,请更换手机号码';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.mobile.message = '请输入正确的手机号码';
					return false;
				}
				return true;
			},
			message: ''
		},
		tel: {
			validator: function(value, param) {
				return /^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?(-\d{1,6})?$/.test(value);	
			},
			message: '请输入正确的固话电话号码'
		},
		mobileAndTel: {
			validator: function(value, param) {
				return /(^([0\+]\d{2,3})\d{3,4}\-\d{3,8}$)|(^([0\+]\d{2,3})\d{3,4}\d{3,8}$)|(^([0\+]\d{2,3}){0,1}13\d{9}$)|(^\d{3,4}\d{3,8}$)|(^\d{3,4}\-\d{3,8}$)/.test(value);
			},
			message: '请输入正确的联系电话或手机号码'
		},
		username : {// 只能输入英文和数字和特殊字符
			validator : function(value, param) {
				/* return /^[a-zA-Z0-9_]{1,}$/.test(value); */
				if(/^[a-zA-Z0-9_]{1,}$/.test(value)){
					if(validatorDataOnlien(value)){
						 $.fn.validatebox.defaults.rules.username.message = '用户名已经存在,请使用其他用户名';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.username.message = '请输入英文、数字或下划线';
					return false;
				}
				return true;
			},
			message : ''
		},
		passwordlegth: {
			validator: function (value) {
				return value.length >= 6;
			},
			message: '密码长度至少6位'
		},
		confirmPassword: {
			validator: function (value, param) {
				return value == $(param[0]).val();
			},
			message: '两次密码不一致'
		}
	});

	</script>
</body>
</html>
